from django.db import models
from equipment.models import Equipment


class TaskBlock(models.Model):
    """
    任务块定义模型
    """
    STATUS_CHOICES = [
        ('active', '激活'),
        ('inactive', '未激活'),
        ('completed', '已完成'),
        ('paused', '暂停'),
    ]
    
    task_name = models.CharField(max_length=200, verbose_name='任务名称')
    duration = models.IntegerField(verbose_name='持续时间(天)')
    required_device = models.ForeignKey(
        Equipment, 
        on_delete=models.CASCADE, 
        verbose_name='所需设备',
        help_text='关联equipment表中的device_name字段',
        null=True,
        blank=True
    )
    daily_device_config = models.TextField(
        verbose_name='按天设备配置',
        help_text='存储每天的设备配置信息，JSON格式'
    )
    status = models.CharField(
        max_length=20, 
        choices=STATUS_CHOICES, 
        default='inactive',
        verbose_name='状态'
    )
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        verbose_name = '任务块定义'
        verbose_name_plural = '任务块定义'
        db_table = 'taskblock'
    
    def __str__(self):
        return f'{self.task_name} - {self.duration}天'
